//
//  Person.m
//  05-HomeWork
//
//  Created by dllo on 16/7/8.
//  Copyright © 2016年 daming. All rights reserved.
//

#import "Person.h"

@implementation Person
//自定义初始化
- (instancetype)initWithName:(NSString *)name age:(NSInteger)age sex:(NSString *)sex{
    self = [super init];
    if (self) {
        _name = name;
        _age = age;
        _sex = sex;
    }
    return self;
}

- (NSString *)description {
    return [NSString stringWithFormat:@"name = %@, age = %ld, sex = %@", _name, _age, _sex];
}
// 根据名字升序排序
- (NSComparisonResult)deSortedByName:(Person *)person {
    return [self.name compare:person.name];
}
// 根据年龄升序排序
- (NSComparisonResult)deSortedByAge:(Person *)person {
    if (self.age > person.age) {
        return NSOrderedDescending;
    } else if (self.age < person.age) {
        return NSOrderedAscending;
    } else {
        return NSOrderedSame;
    }
}
// 根据性别升序排序
- (NSComparisonResult)deSortedBySex:(Person *)person {
    return [self.sex compare:person.sex];
}
@end
